package com.migu.contacts.main.create;

import static com.migu.contacts.net.Service.API;

import android.util.Log;
import android.view.View;

import com.frank.libandroid.BaseActivity;
import com.frank.libandroid.BaseAdapter;
import com.frank.libandroid.butterknife.BindAdapter;
import com.migu.contacts.R;
import com.migu.contacts.bean.Page;
import com.migu.contacts.databinding.ActivityOcrListBinding;
import com.migu.contacts.databinding.ItemOcrBinding;
import com.migu.contacts.net.ResultCallback;

import java.util.List;

public class OcrListActivity extends BaseActivity<ActivityOcrListBinding> {
    @Override
    protected void initData() {
        super.initData();
        API.ocrList(1, 9999).enqueue(new ResultCallback<Page<OcrBean>>() {
            @Override
            protected void onSuccess(Page<OcrListActivity.OcrBean> documentScoreBeans) {
                Log.d(TAG, "onSuccess() called with: documentScoreBeans = [" + documentScoreBeans + "]");
                if (documentScoreBeans != null) {
                    List<OcrBean> list = documentScoreBeans.list;
                    adapter.setData(list);
                }
                if (adapter.getData().size() == 0) {
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                } else {
                    mBinding.emptyView.setVisibility(View.GONE);
                }
            }
        });
    }

    @BindAdapter(R.id.recyclerView)
    BaseAdapter<ItemOcrBinding, OcrBean> adapter = new BaseAdapter<ItemOcrBinding, OcrBean>() {
        @Override
        protected void onBindData(ItemOcrBinding binding, OcrBean bean, int position) {
            super.onBindData(binding, bean, position);
            if (position == mList.size() - 1) {
                binding.emptyView.setVisibility(View.VISIBLE);
            } else {
                binding.emptyView.setVisibility(View.GONE);
            }
        }
    };

    public void go(View view) {
        finish();
    }

    public static class OcrBean {
        public int id;
        public String url;
    }
}